<template>
  <div class="Judges">
    <img src="/static/img/btn_back.png" alt="btn" class="btn" @click="onNavToBack">
    <img src="/static/img/p3_btn_login.png" alt="btn" class="btn-login" @click="onNavTo">
    <div class="items">
      <ul>
        <li v-for="v, k in judges" :key="k">
          <img src="/static/img/test2.png" alt="">
          <div class="name">{{ v.name }}</div>
          <div class="desc">{{ v.desc }}</div>
        </li>
      </ul>
    </div>
    <div class="login" v-if="loginShow">
      <div class="bg">
        <div class="input">
          <label for="account">账号:</label>
          <input type="text" id="account" v-model="form.account" placeholder="请输入您的账号">
        </div>
        <div class="input">
          <label for="password">密码:</label>
          <input type="password" id="password" v-model="form.password" placeholder="请输入您的密码">
        </div>
        <div class="submit" @click="onLoginTo"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { querystring } from 'vux';

export default {
  name: 'Judges',
  data() {
    return {
      judges: [],
      form: {
        account: '',
        password: ''
      },
      loginShow: false
    }
  },
  created() {
    this.$http.get('/judges').then(({data}) => {
      this.judges = data.data;
    });
  },
  methods: {
    onNavToBack() {
      this.$router.go(-1);
    },
    onNavTo() {
      let token = localStorage.getItem('token');
      if (!token) {
        this.loginShow = true;
        return
      }
      this.$router.push(`/judges_teams`);
    },
    onLoginTo() {
      this.$http.post('/judge/login', querystring.stringify(this.form)).then(({data}) => {
        if (data.code != 0) {
          this.$vux.alert.show({
            title: '提示',
            content: data.msg,
          });
          return false;
        }
        localStorage.setItem('token', data.token);
        this.$router.push(`/judges_teams`);
      });
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import "../../assets/scss/common.scss";

.Judges {
  @include bg('/static/img/bg.png');
  display: flex;
  flex-direction: column;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  &::-webkit-scrollbar {
    display: none;
  }
  .btn {
    width: 20%;
    margin: 10px;
  }
  .btn-login {
     position: fixed;
     bottom: 20px;
     right: 20px;
     width:8.48%; 
     height: 15.72%;
  }
  .login {
     position: absolute;
     left: 0;
     top: 0;
     background-color: rgba(0,0,0,.5);
     width: 100%;
     height: 100%;
     .bg {
      @include img('/static/img/p3_bg_login.png', 69.58%, 29.79%, center, center);
      .input {
        position: absolute;
        top: 35%;
        width: 100%;
        text-align: center;
        font-size: 14px;
        color: #333;
        label, input {
          height: 26px;
          line-height: 26px;
        }
        input {
          border: none;
          border-radius: 4px;
          box-sizing: border-box;
          padding: 5px;
          outline: none;
        }
        &:nth-of-type(2) {
          top: 55%;
        }
      }
      .submit {
        @include img('/static/img/p3_btn_ok.png', 40.58%, 18.79%, center, 86%);
      }
     }
  }
  .items {
    box-sizing: border-box;
    padding: 0 10px;
    ul {
      list-style-type: none;
      display: flex;
      flex-wrap: wrap;
      li {
        width: 50%;
        display: flex;
        flex-direction: column;
        font-size: 14px;
        margin-bottom: 20px;
        box-sizing: border-box;
        padding: 0 20px;
        align-items: center;
        img {
          width: 100%;
          border: 3px solid #FDA91A;
          border-radius: 10px;
          margin-bottom: 5px;
          box-shadow: 1px 1px 5px #666;
        }
        .name {
          width: 100%;
          font-size: 14px;
          font-weight: bold;
        }
        .desc {
          @extend .name;
          text-align: justify;
          font-weight: normal;
          height: 4.6em;
          line-height: 1.2em;
          overflow: hidden;
          font-size: 12px;
          color: #333;
        }
      }
    }
  }
}
</style>
